package com.study.rabbit.consumer;

import java.util.Map;
import java.util.Map.Entry;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.MessageProperties;
/**
 * @description TestConsumerListener
 * @author TDW
 * @date 2018年10月29日
 */
public class TestConsumerListener implements MessageListener{
	public void onMessage(Message message) {
		System.out.println("TestConsumerListener监听收到一条消息....");
		MessageProperties properties = message.getMessageProperties();
		Map<String, Object> headers = properties.getHeaders();
		String body = new String(message.getBody());
		
		System.out.println("message headers:");
		for(Entry<String, Object> entry : headers.entrySet()){
			System.out.println("\theader key="+entry.getValue()+",value="+entry.getValue());
		}
		System.out.println("message body="+body);
		String opType = (String) headers.get("op_type");//根据操作类型做相应的业务处理
		switch (opType) {
		case "1000":
			//TODO ....
			break;
		case "2000":
			//TODO ....
			break;
		default:
			break;
		}
		System.out.println("TestConsumerListener消息处理完毕");
		
		
	}
}
